package com.tree.common.config.i18n.util;

import org.apache.commons.lang.StringUtils;

/**
 * @ClassName com.demo.common.i18n.util
 * Description: <类功能描述>. <br>
 * <p>
 * <使用说明>
 * </p>
 * @Author tree
 * @Date 2019-05-24 23:42
 * @Version 1.0
 */
public enum Language {
    zh_CN("zh-CN,zh,zh_cn,zh_sg,zh-sg"),
    zh_TW("zh_TW,zh-hk,zh_tw,zh-tw,zh-Mp,zh-mo"),

    en_US("en_US,en-us,en_gb,en-gb,en-US");


    private String alice;

    Language(String alice) {
        this.alice = alice;
    }

    public String[] alices() {
        return alice.split(",");
    }


    public static Language getLan(String code) {
        if (!StringUtils.isEmpty(code)) {
            for (Language lang : Language.values()) {
                String[] alices = lang.alices();
                for (String alice : alices) {
                    if (alice.equalsIgnoreCase(code) || code.toLowerCase().startsWith(alice)) {
                        return lang;
                    }
                }
            }
        }
        return zh_CN;
    }

}
